| 123456789101112131415161718192021222324252627282930313233343536373839 |
- import { NextRequest, NextResponse } from 'next/server';
- // 정적 리소스 호스트 (배너/팝업/회원 사진/게시판 이미지 등).
- // 로컬: NEXT_PUBLIC_RESOURCE_URL 미설정 시 API_URL 로 폴백 (API 가 wwwroot 정적 서빙).
- // dev/prod: dev-resource.dpot.live / resource.dpot.live 가 Admin/API uploads 통합 서빙.
- const RESOURCE_URL = process.env.NEXT_PUBLIC_RESOURCE_URL || process.env.API_URL;
- export async function GET(_: NextRequest, { params }: { params: Promise<{ path: string[] }> })
- {
- const { path } = await params;
- const filePath = `/uploads/${path.join('/')}`;
- try {
- const res = await fetch(`${RESOURCE_URL}${filePath}`, {
- cache: 'no-store'
- });
- if (!res.ok) {
- return new NextResponse(null, {
- status: res.status
- });
- }
- const contentType = res.headers.get('content-type') || 'application/octet-stream';
- const buffer = await res.arrayBuffer();
- return new NextResponse(buffer, {
- status: 200,
- headers: {
- 'Content-Type': contentType,
- 'Cache-Control': 'public, max-age=31536000, immutable'
- }
- });
- } catch {
- return new NextResponse(null, {
- status: 502
- });
- }
- }
|